# -*- coding: utf-8 -*-

import logging
import threading
import yaml
import time
from pop import activation_account

logging.basicConfig(level=logging.INFO,
                        filename='./log.txt',
                        filemode='w',
                        format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s')


proxies = {
  "http": "http://58.220.95.90:9401"
}

#proxies = None
if __name__ == '__main__':
    mail_server = ""
    port = ""
    with open("./config.yaml") as f:
        config = yaml.load(f, Loader=yaml.FullLoader)
        server = config["mail_server"]["choice"]
        port = config[server]["port"]
        SSL = config[server]["SSL"]
        server = config[server]["pop3_server"]

        server = config[server]["pop3_server"]
    logging.info("mail server   "+ mail_server +   "port  "+  str(port))

    mail_server = {
        "mail_server": server,

        "port": port,
        "SSL":SSL,
        "port": port
    }
    with open("./account.txt", 'r') as f:
        for line in f.readlines():
            account = dict()
            account_list = line.strip().split(",")
            if len(account_list) == 2:
                email = ""
                authority_code = ""
                for i in range(len(account_list)):
                    if i ==0:
                        email = account_list[i].split(":")[1]
                    if i==1:
                        authority_code = account_list[i].split(":")[1]
                try:
                    logging.info("activation account email   "+ email+"  authority_code   "+authority_code +
                                 "    proxies   ")
                    t= threading.Thread(target=activation_account, args=(email,authority_code,mail_server,proxies))
                    t.start()
                    t.join()
                except Exception as e:
                    pass
    logging.info("the scripts has ended ----------------------------------------------------------------------")